<?php
include(APP_PATH.'/Lib/Action/AuthAction.class.php');

class SurveyAction extends AuthAction {

	public function index() {

		$tbl = new Model();
        $ret = $tbl->query('
            SELECT m.uid uid, m.name name, m.university uni, a.aid, aid
            FROM sfem_member m, sfem_abstract a
            WHERE a.uid = m.uid
        ');

        $tReview = M('abst_review');
        $tSurvey = M('survey');

        $tmp1 = 0; $tmp2 = 0;	//次数：通过、表示能在30号之前...

        foreach ($ret as $key=>$abst) {
            $review_ret = $tReview->field('ans')->where("aid={$abst['aid']}")->order('mtime DESC')->find();
            if ($review_ret && $review_ret['ans']) {
                //Passed abstracts
                ++$tmp1;
                $ret[$key]['review'] = true;
                $survey = $tSurvey->field('ans, mtime')->where("uid={$abst['uid']} AND sno=1")->find();
                
                if ($survey) {
                    $ret[$key]['survey'] = $survey['ans'];
                    if ($survey['ans']) ++$tmp2;
                    $ret[$key]['mtime'] = $survey['mtime'];
                } else {
                    $ret[$key]['survey'] = -1;
                }
                
            }
        }
        $this->assign('list', $ret);
        $this->assign('count', array(
        	'all' => $tmp1,
        	'can' => $tmp2,
        	'precent' => round($tmp2/$tmp1, 2) * 100
        ));
        $this->display();
	}
}






